const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const SystemLogs = sequelize.define('SystemLogs', {
  id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    autoIncrement: true,
    comment: '日志ID',
  },
  userId: {
    type: DataTypes.BIGINT,
    comment: '用户ID',
  },
  level: {
    type: DataTypes.ENUM,
    allowNull: false,
    comment: '日志级别',
  },
  category: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '日志分类',
  },
  message: {
    type: DataTypes.TEXT,
    allowNull: false,
    comment: '日志消息',
  },
  details: {
    type: DataTypes.JSON,
    comment: '详细信息',
  },
  ipAddress: {
    type: DataTypes.STRING(45),
    comment: 'IP地址',
  },
  userAgent: {
    type: DataTypes.TEXT,
    comment: '用户代理',
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '创建时间',
  }
}, {
  tableName: 'system_logs',
  comment: '系统日志表',
  timestamps: true,
  paranoid: true,
  underscored: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  deletedAt: 'deleted_at'
});

module.exports = SystemLogs;
